home *** CD-ROM | disk | FTP | other *** search
- Path: news.ov.com!news
- From: glenn@ov.com (Fletcher.Glenn@ov.com)
- Newsgroups: comp.lang.c
- Subject: Re: A weird thing about printf()
- Date: 10 Apr 1996 21:10:09 GMT
- Organization: OpenVision
- Message-ID: <4kh83h$fml@spanky.pls.ov.com>
- References: <4kflr2$5if@dewey.csun.edu>
- Reply-To: glenn@ov.com
- NNTP-Posting-Host: foghorn.pls.ov.com
-
- In article 5if@dewey.csun.edu, kc44097@csun.edu (chen) writes:
- >
- >
- > The program :
- >
- >#include <stdio.h>
- >
- >int answer;
- >main()
- >{
- > answer=2+2;
- > printf("The answer is %d\n");
- > return 0;
- >}
- >
- > In printf(),I lost "answer" in the end,but it works,and give me the
- >result 0.I wonder how the compiler handle this condition.Also,is this
- >allow by C?(by this, I mean is this a leagal usage in language itself,
- >or just a mistake cause by the compiler?)
- >
- > Can someone give me some advice ? Please e-mail me :
- > kc44097@huey.csun.edu
- >
- > Thankx !!!!!!
-
-
- You are lucky that you did not get a segment violation or other error.
- The "%d" tells printf that there is an argument. In not supplying the
- argument, you accept whatever the system does to read a non-existent
- argument. The compiler is (usually) incapable of checking for the
- correct number of arguments in a variable argument function (such
- as printf).
-
- Fletcher.Glenn@ov.com
-
-
-